package com.atguigu.guli.service.edu.service.impl;

import com.atguigu.guli.service.edu.entity.Teacher;
import com.atguigu.guli.service.edu.entity.TeacherQuery;
import com.atguigu.guli.service.edu.mapper.TeacherMapper;
import com.atguigu.guli.service.edu.service.TeacherService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

/**
 * <p>
 * 讲师 服务实现类
 * </p>
 *
 * @author gyf
 * @since 2020-09-20
 */
@Service
public class TeacherServiceImpl extends ServiceImpl<TeacherMapper, Teacher> implements TeacherService {
//查询教师方法teacherQuery
    @Override
    public Page<Teacher> selectPage(Page<Teacher> pageModel, TeacherQuery teacherQuery) {

        QueryWrapper<Teacher> wrapper = new QueryWrapper<>();
        //按类型排序
        wrapper.orderByAsc("sort");
        //如果没有参数
        if(teacherQuery==null){
            return baseMapper.selectPage(pageModel,wrapper);
        }

        //获取查询对象属性
        String name = teacherQuery.getName();
        Integer level = teacherQuery.getLevel();
        String joinDateBegin = teacherQuery.getJoinDateBegin();
        String joinDateEnd = teacherQuery.getJoinDateEnd();

    if(!StringUtils.isEmpty(name)){
        wrapper.likeRight("name",name);
        return baseMapper.selectPage(pageModel,wrapper);
    }
    if(level!=null){
        wrapper.eq("level",level);
        return baseMapper.selectPage(pageModel,wrapper);

    }
    if(!StringUtils.isEmpty(joinDateBegin)){
         wrapper.ge("join_date",joinDateBegin);
        return baseMapper.selectPage(pageModel,wrapper);
    }

    if(!StringUtils.isEmpty(joinDateEnd)){
         wrapper.le("join_date",joinDateEnd);
        return baseMapper.selectPage(pageModel,wrapper);
    }
        return baseMapper.selectPage(pageModel,wrapper);
    }
}
